package com.aptg;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class PromotionAll {

	public static void main(String[] args) throws IOException {
		try {
			String sql = null;
			
			File file = new File("E://eshop_oes_data//promotion_all.txt");
			BufferedReader brdFile = new BufferedReader(new FileReader(file));
			// BufferedReader brdFile = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"));
			String strLine = null;

			File outFile = new File("E://eshop_oes_data//promotion_all.sql");
			BufferedWriter writer = new BufferedWriter(new FileWriter(outFile));
			
			while ((strLine = brdFile.readLine()) != null) {
				String[] data = strLine.split(",");
				
				data[4] = "".equals(data[4]) ? null : "'" + data[4] + "'";
				data[5] = "".equals(data[5]) ? null : "'" + data[5] + "'";
				data[19] = "".equals(data[19]) ? null : data[19];
				
				sql = "";
				sql += "insert into apt_promotion_all (promo_code, promo_shcode, promo_des, promo_content, apply_str_date, apply_end_date, remark, product_type, promo_group_id, promo_point_limit, mgm_flag, addservice_flag, bill_months, limit_bill_amount, promotion_type, retention_type, short_term_retention, cws_flag, fnz_flag, retention_months, promo_shdes, sms_notice, customer_limit, addservice_count, limit_bill_type, group_flag, update_time)";
				sql += " values ('" + data[0] + "','" + data[1] + "','" + data[2] + "','" + data[3] + "'," + data[4] + "," + data[5] + ",'" + data[6] + "','" + data[7] + "','" + data[8] + "','" + data[9] + "','" + data[10] + "','" + data[11] + "','" + data[12] + "','" + data[13] + "','" + data[14] + "','" + data[15] + "','" + data[16] + "','" + data[17] + "','" + data[18] + "'," + data[19] + ",'" + data[20] + "','" + data[21] + "','" + data[22] + "','" + data[23] + "','" + data[24] + "','" + data[25] + "','2011-01-18 03:23:06')";
				sql += ";\r\n";
				
				writer.write(sql);
			}
			
			brdFile.close();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
